import { createApp } from "vue";
import pinia from "@/pinia/pinia.ts";
import router from "@/router/router.ts";
import App from "@/App.vue";
import "@/styles/index.scss";

import { renderWithQiankun, qiankunWindow } from "vite-plugin-qiankun/dist/helper";
import type { QiankunLifeCycle, QiankunProps } from "vite-plugin-qiankun/es/helper";

const object: QiankunLifeCycle = {
  mount(props: QiankunProps) {
    render(props);
    console.log("mount", props);
  },
  bootstrap() {
    console.log("bootstrap");
  },
  unmount(props: QiankunProps) {
    console.log("unmount", props);
  },
  update(props: QiankunProps) {
    console.log("update", props);

  },
};
// 使用乾坤渲染
renderWithQiankun(object);

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}

function render(props: any = {}) {
  const { container } = props;
  const app = createApp(App);
  app.use(pinia);
  app.use(router);
  app.mount(container ? container.querySelector("#app") : "#app");
}
